package com.csu.chart;

import org.jfree.chart.renderer.category.StandardBarPainter;

import java.awt.*;

public class BarRenderer extends org.jfree.chart.renderer.category.BarRenderer {

    private Paint[] colors;
    //初始化柱子颜色
    private String[] colorValues = { "D2E5F3" }; //颜色库

    public BarRenderer() {
        colors = new Paint[colorValues.length];
        for (int i = 0; i < colorValues.length; i++) {
//            colors[i] = Color.decode(colorValues[i]);
            colors[i] = new Color(200,222,240);
        }
        setBarPainter(new StandardBarPainter()); //设置柱体为平面
        setShadowVisible(false);//设置柱体阴影
        setMaximumBarWidth(0.08);//设置柱体宽度
        setItemMargin(0.1f);
    }


    public BarRenderer(Color color) {
        colors = new Paint[colorValues.length];
        for (int i = 0; i < colorValues.length; i++) {
            colors[i] = color;
        }
        setBarPainter(new StandardBarPainter()); //设置柱体为平面
//        setShadowVisible(true);//设置柱体阴影
//        setShadowPaint(Color.LIGHT_GRAY);
        setShadowVisible(false);
        setMaximumBarWidth(0.08);//设置柱体宽度
        setItemMargin(0.1f);
    }

    //每根柱子以初始化的颜色不断轮循
    public Paint getItemPaint(int i, int j) {
        return colors[j % colors.length];
    }

}
